This page contains SQL Server queries that can help with analyzing problems related to the Dynamics CRM Asynchronous Processing Service.
List async operations that are in a Ready state but are Waiting or Waiting for Resources
SELECT Name,COUNT(Name)AS RecordCount FROM AsyncOperationBase WITH (NOLOCK) WHERE StateCode = 0 AND (StatusCode = 0 OR StatusCode = 10) GROUPBY Name ORDERBY 2 DESC
# Rows in the async-related tables
SELECT COUNT(*) FROM AsyncOperationBase SELECT COUNT(*) FROM PrincipalObjectAccess SELECT COUNT(*) FROM WorkflowLogBase
Determine number of minutes between the created date/time for an async job and when it’s completed
SELECT TOP 1 DATEDIFF(MI, CompletedOn, CreatedOn)*-1 FROM AsyncOperationBase] WHERE StateCode = 3 -- Completed ORDER BY CompletedOn DESC
Count async jobs by operation type, status code and state code
SELECT OperationType, StatusCode, StateCode, COUNT(*) AS NumRecords FROM AsyncOperationBase WITH (NOLOCK) WHERE StatusCode <> 30 AND StatusCode <> 31 GROUP BY OperationType, StatusCode, StateCode ORDER BY 4 DESC
Count async jobs that are successful (and can be removed from the table)
SELECT COUNT(AsyncOperationId) FROM AsyncOperationBase WITH (NOLOCK) WHERE OperationType in (1, 9, 12, 25, 27, 10) AND StateCode = 3 AND StatusCode IN (30,32)
Show the name and count of async jobs added in last 1 minute
SELECT Name, COUNT(*) FROM AsyncOperationBase WHERE DATEDIFF(MI, CreatedOn, GETUTCDATE()) < 1 GROUP BY Name ORDER BY 2 DESC
Number of async jobs completed in the last N minutes
SELECT COUNT(*) FROM AsyncOperationBase WHERE StateCode = 3 AND DATEDIFF(MI, CompletedOn, GETUTCDATE()) < 1
List async operations that are in a Ready state but are Waiting or Waiting for Resources
SELECT Name,COUNT(Name)AS RecordCount
FROM AsyncOperationBase WITH (NOLOCK)
WHERE StateCode = 0 AND (StatusCode = 0 OR StatusCode = 10)
GROUPBY Name
ORDERBY 2 DESC
# Rows in the async-related tables
SELECT COUNT(*) FROM AsyncOperationBaseSELECT COUNT(*) FROM PrincipalObjectAccess
SELECT COUNT(*) FROM WorkflowLogBase
Determine number of minutes between the created date/time for an async job and when it’s completed
SELECT TOP 1 DATEDIFF(MI, CompletedOn, CreatedOn)*-1FROM AsyncOperationBase]
WHERE StateCode = 3 -- Completed
ORDER BY CompletedOn DESC
Count async jobs by operation type, status code and state code
SELECT OperationType, StatusCode, StateCode, COUNT(*) AS NumRecordsFROM AsyncOperationBase WITH (NOLOCK)
WHERE StatusCode <> 30 AND StatusCode <> 31
GROUP BY OperationType, StatusCode, StateCode
ORDER BY 4 DESC
Count async jobs that are successful (and can be removed from the table)
SELECT COUNT(AsyncOperationId)FROM AsyncOperationBase WITH (NOLOCK)
WHERE OperationType in (1, 9, 12, 25, 27, 10)
AND StateCode = 3 AND StatusCode IN (30,32)
Show the name and count of async jobs added in last 1 minute
SELECT Name, COUNT(*)FROM AsyncOperationBase
WHERE DATEDIFF(MI, CreatedOn, GETUTCDATE()) < 1
GROUP BY Name
ORDER BY 2 DESC
Number of async jobs completed in the last N minutes
SELECT COUNT(*)FROM AsyncOperationBase
WHERE StateCode = 3
AND DATEDIFF(MI, CompletedOn, GETUTCDATE()) < 1